﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace XnaGameStudio1
{
    //-----------------------------------------------------------------------------------------------
    class XnaView : Panel, IServiceProvider
    {
        private XnaGraphicsDevice graphics;
        private ContentManager contentManager;

        public GraphicsDevice GraphicsDevice
        {
            get { return graphics.GraphicsDevice; }
        }

        //-------------------------------------------------------------------------------------------
        public XnaView()
        {
            graphics = new XnaGraphicsDevice(this);
            graphics.CreateDevice();
            contentManager = new ContentManager(this);
        }

        public bool BeginDraw()
        {
            return graphics.BeginDraw();
        }

        public void EndDraw()
        {
            graphics.EndDraw();
        }

        public void Clear(Color color)
        {
            graphics.GraphicsDevice.Clear(color);
        }


        //-------------------------------------------------------------------------------------------
        #region IServiceProvider Members
        //------------------------------------------------------------------------------------------------
            
        //------------------------------------------------------------------------------------------------
            public new object GetService(Type serviceType)
            {
                if ( serviceType == typeof( Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService ) )
                {
                    return graphics;
                }
                else
                {
                    return base.GetService(serviceType);
                }
            }

            private void InitializeComponent()
            {
                this.SuspendLayout();
                this.ResumeLayout(false);

            }

        //------------------------------------------------------------------------------------------------
        #endregion
        //-------------------------------------------------------------------------------------------
    }
}
